package com.coder520.topic.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.coder520.topic.dao.TabTopicMapper;
import com.coder520.topic.entity.TabTopic;
import com.coder520.topic.service.TabTopicService;
@Service("tabTopicService")
public class TabTopicServiceImpl implements TabTopicService{
	private static final String DELETEMARK="N";
	private static final String NODELETEMARK="Y";
	@Autowired
	private TabTopicMapper tabTopicMapper;
	/**
	 * 查询条件查询
	 */
	@Override
	public List<TabTopic> query(Map<String, String> map) {
		return tabTopicMapper.getAllTabTopic(map);
	}

	/**
	 * 保存更新
	 */
	@Override
	public int save(TabTopic tabTopic) {
		// TODO Auto-generated method stub
		int type=0;
		if (StringUtils.isEmpty(tabTopic.getTopicId())) {
			tabTopic.setTopicId(UUID.randomUUID().toString());
			tabTopic.setDeleteMark(NODELETEMARK);
			type=tabTopicMapper.insert(tabTopic);
		}else {
			type=tabTopicMapper.updateByPrimaryKeySelective(tabTopic);
		}
		return type;
	}
	/**
	 * 逻辑删除
	 */
	@Override
	public int delete(String topicId) {
		TabTopic record=new TabTopic();
		record.setTopicId(topicId);
		record.setDeleteMark(DELETEMARK);
		return tabTopicMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public TabTopic queryById(String tabTopicId) {
		// TODO Auto-generated method stub
		return tabTopicMapper.selectByPrimaryKey(tabTopicId);
	}
}
